<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增专题')"/>
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-subject-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input class="form-control" name="title" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">副标题：</label>
            <div class="col-sm-8">
                <input class="form-control" name="subtitle" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">开始时间</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="startTime" class="form-control" placeholder="yyyy-mm-dd hh:ii:ss" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">结束时间</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="endTime" class="form-control" placeholder="yyyy-mm-dd hh:ii:ss" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">专题主图</label>
            <input name="pic" type="hidden">
            <div class="col-sm-8">
                <div class="file-loading">
                    <input name="file" id="fileinput-demo-1" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">专题轮播图</label>
            <input name="albumPics" type="hidden" id="albumPics">
            <div class="col-sm-8">
                <div class="file-loading">
                    <input name="file" id="fileinput-demo-2" type="file" multiple>
                </div>
            </div>
        </div>
        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">画册图片用逗号分割：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<input class="form-control" name="albumPics" type="text">-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea class="form-control" name="description"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">显示状态</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('subject_show_status')}">
                    <input type="radio" th:id="${dict.dictCode}" name="showStatus" th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "mall/subject"
    $("#form-subject-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-subject-add').serialize());
        }
    }

    $("#fileinput-demo-1").fileinput({
        'theme': 'explorer-fas',
        'uploadUrl': ctx + 'aliyun/upload',
        overwriteInitial: false,
        autoReplace: true,
        initialPreviewAsData: true,
        initialPreview: [//初始显示图片列表
        ]
    }).on("fileuploaded", function (event, data, previewId, index) {//上传成功回调
        console.log(data.response);
        $("input[name='pic']").val(data.response.url);
    });


    $("input[name='startTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        minView: "month",
        autoclose: true
    });

    $("input[name='endTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        minView: "month",
        autoclose: true
    });

    /**
     * 多张图片上传，逗号分割
     */
    $("#fileinput-demo-2").fileinput({
        'theme': 'explorer-fas',
        'uploadUrl': ctx + 'aliyun/upload',
        overwriteInitial: false,
        autoReplace: true,
        initialPreviewAsData: true,
        initialPreview: [//初始显示图片列表
        ]
    }).on("fileuploaded", function (event, data, previewId, index) {//上传成功回调
        console.log(data.response);
        var a=$("input[name='albumPics']").val();
        if(a.indexOf(",") != -1){ // 包含
            a=a+","+data.response.url;
        }else { // 不包含，第一个
            a=data.response.url+"";
        }
        $("input[name='albumPics']").val(a);
    });

</script>
</body>
</html>
